#define _CRT_SECURE_NO_WARNINGS
#include"SeqList.h"
void SeqList::JudgeCapacity(SeqList* sl)
{
	if (size == capacity)
	{
		int newcapacity = capacity == 0 ? 4 : capacity * 2;
		Datetype* ptr = (Datetype*)realloc(arr,sizeof(Datetype) * newcapacity);
		if (ptr == NULL)
		{
			perror("realloc:");
			exit(1);
		}
		arr = ptr;
		capacity = newcapacity;
	}
}
SeqList::SeqList()
{
	arr = NULL;
	size = capacity = 0;
}
void SeqList::PushBack(SeqList* sl, int x)
{
	JudgeCapacity(sl);
	arr[size++] = x;
}
void SeqList::PushFront(SeqList* sl, int x)
{
	JudgeCapacity(sl);
	int i = size;
	while (i > 0)
	{
		arr[i] = arr[i - 1];
		i--;
	}
	arr[0] = x;
	size++;
}
void SeqList::PopBack(SeqList* sl)
{
	assert(size != 0);
	size--;
}
void SeqList::PopFront(SeqList* sl)
{
	assert(size != 0);
	int i = 0;
	while (i < size - 1)
	{
		arr[i] = arr[i + 1];
		i++;
	}
	size--;
}
void SeqList::Print(SeqList sl)
{
	assert(size != 0);
	for (int i = 0; i < size; i++)
	{
		cout << arr[i] << " ";
	}
	cout << endl;
}
void SeqList::DestorySeqList(SeqList* sl)
{
	if (size == 0)
	{
		return;
	}
	free(arr);
	size = capacity = 0;
	arr = NULL;
}
